package com.hkw.servlet;

import com.hkw.service.IClassRoomService;
import com.hkw.service.impl.ClassRoomServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 删除教室Servlet
 */
@WebServlet(name = "DelClassRoomServlet" ,urlPatterns = "/delClassRoom")
public class DelClassRoomServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        IClassRoomService classRoomService = new ClassRoomServiceImpl();
        int update = classRoomService.delClassRoom(Integer.parseInt(id));
        if(update == 1){
            System.out.println("删除班级成功!");
            request.setAttribute("delClassOk","删除班级成功!");
            request.getRequestDispatcher("classRoomList").forward(request,response);
        }else{
            System.out.println("班级还有人无法删除!");
            request.setAttribute("delClassFail","删除班级失败,班级还有人!");
            request.getRequestDispatcher("classRoomList").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
